package com.edu.exam.enums;

/**
 * 监考安排冲突类型枚举
 *
 * <p>定义监考安排中可能出现的各种冲突类型，包括时间冲突、角色冲突、资质冲突等。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-12
 */
public enum AssignmentConflictType {
    TIME_CONFLICT("TIME_CONFLICT", "时间冲突"),
    ROLE_CONFLICT("ROLE_CONFLICT", "角色冲突"),
    QUALIFICATION_CONFLICT("QUALIFICATION_CONFLICT", "资质冲突"),
    WORKLOAD_CONFLICT("WORKLOAD_CONFLICT", "工作量冲突"),
    AVAILABILITY_CONFLICT("AVAILABILITY_CONFLICT", "可用时间冲突"),
    DUPLICATE_ASSIGNMENT("DUPLICATE_ASSIGNMENT", "重复安排"),
    LOCATION_CONFLICT("LOCATION_CONFLICT", "地点冲突"),
    OTHER("OTHER", "其他");

    private final String code;
    private final String description;

    AssignmentConflictType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static AssignmentConflictType fromCode(String code) {
        for (AssignmentConflictType type : AssignmentConflictType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown assignment conflict type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static AssignmentConflictType fromDescription(String description) {
        for (AssignmentConflictType type : AssignmentConflictType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown assignment conflict type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}